<?php session_start(); ?>
	
<!DOCTYPE html>
<html>
	<head>
		<title>Cameleon events - Sorties et Evénements en France</title>
       	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" href="../Vue/CSS/mot_de_passe_oublie.css" />
	</head>
	
	<body>
		<?php 
			function mdp() {
				$motDePasse = "";
			 	$caracteres = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&~\"#'{([-|`_\^@)]=}$*,?;.:/!<>";
				$longueur = strlen($caracteres);
			
				for($i = 1; $i <= 12; ++$i) {
					$aleatoire = mt_rand(0, ($longueur-1));
					$caractere = $caracteres{$aleatoire};
					$motDePasse = $motDePasse.''.$caractere;
				}
				return $motDePasse;
			}
		
			if(isset($_POST['mail'])) {
				$headers = 'Content-type: text/html; charset=UTF-8'."\r\n".'From: no-reply@cameleonevents.fr'."\r\n";
				$to = $_POST['mail']; 
    			$objet = '[Cameleon Events] Votre nouveau mot de passe';
				$pass = mdp();
				$message = 'Votre nouveau mot-de-passe est : '.$pass;
	
    			include('../Modele/mot_de_passe_oublie.php');
				$reponse = modificationMdp($pass, $to);
				if($reponse) {
					mail($to, $objet, $message, $headers);	
					$statut_mail = "Envoyé";		
				} else {
					$statut_mail = "Invalide";
				}
			}
			include('../Vue/mot_de_passe_oublie.php');
		?>
	</body>
</html>